<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "{{%edu_collection}}".
 *
 * @property integer $collect_id
 * @property integer $user_id
 * @property integer $collect_type
 * @property integer $model_id
 * @property integer $collect_addtime
 */
class Collection extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%collection}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'collect_type', 'model_id', 'collect_addtime'], 'required'],
            [['user_id', 'collect_type', 'model_id', 'collect_addtime'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'collect_id' => 'Collect ID',
            'user_id' => 'User ID',
            'collect_type' => 'Collect Type',
            'model_id' => 'Model ID',
            'collect_addtime' => 'Collect Addtime',
        ];
    }

    public function collect($user_id,$model_id,$type)
    {
        return $this -> find()
                     -> where(['and',['=','user_id',$user_id],['=','model_id',$model_id],['=','collect_type',$type]])
                     -> asArray()
                     -> one();
    }
}
